package com.nh.action;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.nh.entity.GKLBook;
import com.nh.entity.GKLBookType;

public class GKLBookAction extends BaseAction {
	private GKLBook book;
	private Long optionId;
	private Long classTypeId;

	public String bookList() {
		Criteria criteria = this.createCriteria(GKLBook.class);
		// criteria.addOrder(Order.desc("publishTime"));
		// criteria.addOrder(Order.desc("orderInfo"));
		if (null != classTypeId) {
			criteria.add(Restrictions.eq("classType.id", classTypeId));
		}
		this.queryByPage(criteria, "gKLBookAction!bookList.action", 10);
		return "bookList";
	}

	public String bookAdd() {
		book = new GKLBook();
		return "bookAdd";
	}

	public String bookSave() {
		if (null == book.getId()) {
			GKLBookType temp=this.getBaseService().findById(classTypeId, GKLBookType.class); 
			book.setClassType(temp);
			this.getBaseService().save(book);
		} else {
			this.getBaseService().saveOrUpdate(book, GKLBook.class);
		}
		return bookList();
	}

	public String bookModify() {
		book = this.getBaseService().findById(optionId, GKLBook.class);
		return "bookAdd";
	}

	public String bookRemove() {
		this.getBaseService().delete(optionId, GKLBook.class);
		return bookList();
	}

	public String bookDetail() {
		book = this.getBaseService().findById(optionId, GKLBook.class);
		return "bookDetail";
	}

	public GKLBook getBook() {
		return book;
	}

	public void setBook(GKLBook book) {
		this.book = book;
	}

	public Long getOptionId() {
		return optionId;
	}

	public void setOptionId(Long optionId) {
		this.optionId = optionId;
	}

	public Long getClassTypeId() {
		return classTypeId;
	}

	public void setClassTypeId(Long classTypeId) {
		this.classTypeId = classTypeId;
	}

}
